﻿using System;

namespace Phoenix.Xna.Framework.Input
{
    /// <summary>
    /// Base class for input state managers.
    /// </summary>
    /// <typeparam name="T">The type of state object to track.</typeparam>
    internal abstract class InputStateManager<T>
    {
        /// <summary>
        /// Raised when the state of the input device has changed.
        /// </summary>
        public event EventHandler StateChanged;

        /// <summary>
        /// Gets the current state of the input device.
        /// </summary>
        public T CurrentState { get; protected set; }

        /// <summary>
        /// Gets the previous state of the input device.
        /// </summary>
        public T PreviousState { get; protected set; }

        /// <summary>
        /// Updates the states for the input device.
        /// </summary>
        public virtual void Update()
        {
            if (!CurrentState.Equals(PreviousState))
            {
                EventHandler handler = StateChanged;

                if (handler != null)
                {
                    handler(null, new InputDeviceStateEventArgs<T>()
                    {
                        CurrentState = CurrentState,
                        PreviousState = PreviousState
                    });
                }
            }
        }
    }
}
